package org.jeecg.modules.zhima.portal.config;

import org.jeecg.modules.zhima.pay.core.annotation.ResourceFactoryComponent;
import org.jeecg.modules.zhima.pay.core.common.RedisResourceFactory;
import org.springframework.beans.factory.annotation.Value;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

@ResourceFactoryComponent
public class RedisResourceFactoryImpl implements RedisResourceFactory {

    @Value("${spring.redis.host}")
    private String host;

    @Value("${spring.redis.port}")
    private int port;

    @Value("${spring.redis.timeout:0}")
    private int timeout;

    @Value("${spring.redis.lettuce.pool.max-idle}")
    private int maxIdle;

//    @Value("${spring.redis.lettuce.pool.max-wait}")
//    private long maxWaitMillis;

    @Value("${spring.redis.password}")
    private String password;

    @Override
    public JedisPool getJedisPool() {
    	/*
    	  框架不关心JedisPool是怎么来的
    	  这里的RedisService是我自己实现的服务
    	  根据项目实际情况换成你自己的实现
    	*/
        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
        jedisPoolConfig.setMaxIdle(maxIdle);
//        jedisPoolConfig.setMaxWaitMillis(maxWaitMillis);
        jedisPoolConfig.setMaxWaitMillis(-1);

        JedisPool jedisPool = new JedisPool(jedisPoolConfig, host, port, timeout, password);
        return jedisPool;
    }
}
